package org.foundation.jala.jamerzip.view;

import java.awt.Dimension;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.foundation.jala.jamerzip.components.JamerElement;

public class InformationView extends JDialog{

	private static final long serialVersionUID = 1L;
	private DataPanelView name,crc,compressSize,realSize,date;
	
	public InformationView(JFrame father) {
		super(father,"Information");
		configuration();
		initComponents();
	}
	
	public void fillData(JamerElement element){
		this.name.setText(element.getName());
		this.crc.setText(""+element.getCrc());
		this.compressSize.setText(""+element.getCompressionSize());
		this.realSize.setText(""+element.getOriginalSize());
		this.date.setText(""+element.getLastModificationDate());
		this.show();
	}

	private void initComponents() {
		name = new DataPanelView("		", "Name :");
		crc = new DataPanelView("		",  "Crc  :");
		compressSize = new DataPanelView("		", "Compress :");
		realSize = new DataPanelView("		", "Real : ");
		date = new DataPanelView("		", "Date : ");
		JPanel all = new JPanel();
		all.setLayout(new BoxLayout(all, BoxLayout.Y_AXIS));
		all.setPreferredSize(new Dimension(350, 400));
		all.setMaximumSize(new Dimension(350, 400));
		all.setBorder(BorderFactory.createEmptyBorder(20, 10, 50, 20));
		all.add(name);
		all.add(crc);
		all.add(compressSize);
		all.add(realSize);
		all.add(date);
		JButton ok = new JButton("Ok");
		ok.addActionListener(new AbstractAction() {
			private static final long serialVersionUID = 1L;

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		all.add(ok);
		ok.setAlignmentX(JButton.CENTER_ALIGNMENT);
		add(all);	
	}

	private void configuration() {
		  this.setSize(400, 380);
	       this.setMinimumSize(new Dimension(400,380));
	       this.setLocationRelativeTo(null);
	       this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
	       this.setModal(true);
	       this.setResizable(false);
	}
}
